package com.sugon.dao;

import com.sugon.entity.SparePartReplaceRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 入库记录Dao
 *
 * @author YuXD
 * @date 2023-06-23
 */
public interface SparePartReplaceRecordDao extends BaseDao<SparePartReplaceRecord> {

    /**
     * 找到指定关键备件正在使用中的换件记录
     *
     * @param sparePartKeyId 关键备件ID
     * @return
     */
    @Select("SELECT * FROM SPARE_PART_REPLACE_RECORD WHERE SPARE_PART_KEY_ID = #{sparePartKeyId} AND RETIRE_TIME IS NULL")
    SparePartReplaceRecord findOngoingReplaceRecord(@Param("sparePartKeyId") String sparePartKeyId);

    /**
     * 找到指定备件耗用记录关联的备件使用寿命周期记录
     *
     * @param consumeRecordId 备件耗用记录ID
     * @return
     */
    @Select("SELECT * FROM SPARE_PART_REPLACE_RECORD WHERE CONSUME_RECORD_ID = #{consumeRecordId}")
    SparePartReplaceRecord queryByConsumeRecordId(@Param("consumeRecordId") String consumeRecordId);

}
